﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Portal.Core;
using Portal.Systems.Model;
using Portal.Utility;
using System.Collections.Specialized;
using System.Web;

namespace Portal.Web.Utility
{
    public class WebEnvironments
    {
        public static SiteParam CreateSiteParam(string SiteId)
        {
            SiteParam OSiteParam = SiteParamUtility.CreateSiteParam(SiteId, WebConfig.XmlSiteConfigFile);
            return OSiteParam;
        }
        public static string Request(string SiteId, string Param)
        {

            string Value = string.Empty;
            if (System.Web.HttpContext.Current.Request[Param] != null)
                Value = (string)System.Web.HttpContext.Current.Request[Param];
            return Value;
        }

        NameValueCollection QueryStrings = GetQueryStrings();

        private static NameValueCollection GetQueryStrings()
        {
            string url;
            if (HttpContext.Current.Request.RawUrl.IndexOf("%3F") != -1)
            {
                url = HttpContext.Current.Server.UrlDecode(HttpContext.Current.Request.RawUrl);
            }
            else
            {
                url = HttpContext.Current.Request.RawUrl;
            }
            if (url.IndexOf("?") != -1)
            {
                string search = url.Split(new char[] { '?' }, StringSplitOptions.RemoveEmptyEntries)[1];
                string[] pairs = search.Split(new char[] { '&' }, StringSplitOptions.RemoveEmptyEntries);
                NameValueCollection result = new NameValueCollection();
                foreach (string p in pairs)
                {
                    string[] nameValue = p.Split(new char[] { '=' }, StringSplitOptions.RemoveEmptyEntries);
                    result.Add(nameValue[0], nameValue[1]);
                }
                return result;
            }
            return new NameValueCollection();
        }

    }
}









